<?php	
	header("Content-Type: text/html;charset=utf-8");

	include("../function/_nosql.php"); //

	include("../function/function.php");
	function str_count($sql,$str){

 $res = mysql_query($sql);

 $num = mysql_num_rows($res);

 $count = 0;

  if($num>0){

	while($arr=mysql_fetch_array($res)){

	 $count = $count + $arr[$str];

	}

  }

  return $count;

}	
	if(IS_AJAX){
		if($_GET['zi'] == 'dong'){
			if($_SESSION['kboy_user'] == "" && $_SESSION['kboy_phone'] == "" || $_SESSION['kboy_userid'] == ""){
				if(!empty($_COOKIE['username'])||！empty($_COOKIE['password'])){//如果session为空，并且用户没有选择记录登录状
						$user_email = $_COOKIE['username'];
						$user_password = $_COOKIE['password'];
						$is_reguser = getNewsNums("kboy_user"," ( user_email='$user_email' or user_phone='$user_email' )  AND user_password='$user_password'");
						if($is_reguser >0){
							$_SESSION['kboy_user'] = $user_email;
			
							$_SESSION['kboy_userid'] = getClassName("kboy_user","uid","( user_email='$user_email' or user_phone='$user_email' )");
			
							$_SESSION['kboy_leader'] = getClassName("kboy_user","user_leader","( user_email='$user_email' or user_phone='$user_email' )");
							
							mysql_query("update kboy_user set user_lasttime='$THIS_TODAY_DATETIME',user_lastip='".getip()."' where ( user_email='$user_email' or user_phone='$user_email' )");
							echo json_encode(array('msg'=>'登陆成功','status'=>'1'));
							exit;
						}else{
							echo json_encode(array('msg'=>'自动登陆失败'));
							exit;
						}
				}else{
					
				}
			}else{
				echo json_encode(array('msg'=>'登陆成功','status'=>'1'));
			}
		}
		if($_GET['log'] == 'login'){
			$user_email = chkstr(trim($_REQUEST['account']));
			$user_password = chkstr(trim($_REQUEST['password']));
			
			if(strlen($user_email)<1){
			echo json_encode(array('msg'=>'手机号不能为空'));
			die;
			}
			if(strlen($user_password)<1){
			echo json_encode(array('msg'=>'密码不能为空'));
			die;
			}
			$user_password = md5(md5($user_password));

			$is_reguser = getNewsNums("kboy_user"," ( user_email='$user_email' or user_phone='$user_email' )  AND user_password='$user_password'");
			if($is_reguser >0){
	
				$_SESSION['kboy_user'] = $user_email;
	
				$_SESSION['kboy_userid'] = getClassName("kboy_user","uid","( user_email='$user_email' or user_phone='$user_email' )");
	
				$_SESSION['kboy_leader'] = getClassName("kboy_user","user_leader","( user_email='$user_email' or user_phone='$user_email' )");
				
				setcookie("username",$user_email,time()+3600*24*365);
   				setcookie("password",$user_password,time()+3600*24*365);
				mysql_query("update kboy_user set user_lasttime='$THIS_TODAY_DATETIME',user_lastip='".getip()."' where ( user_email='$user_email' or user_phone='$user_email' )");
				echo json_encode(array('msg'=>'登陆成功','status'=>'1'));
			}else{
				echo json_encode(array('msg'=>'登陆失败'));
				}
		}
		if($_GET['huodong']=='lists'){
			$kboy_userid = $_SESSION['kboy_userid'];
			$time = date("Y-m=d H:i:s");
			$news_sql = "select id,active_title,active_pic,active_start_time from  kboy_forum_active where uid=$kboy_userid and active_model = 0 and active_end_time > '$time' order by active_start_time asc";
			$news_rows = mysql_query($news_sql);
			while($news_rs = mysql_fetch_array($news_rows)){
				$asd[]=$news_rs;
			}
			foreach ($asd as $key => $value) {
									$asd[$key]['active_start_time']=date('Y-m-d',strtotime($value['active_start_time']));
									$active_sollimg = explode(',',$value['active_pic']);
									$asd[$key]['active_sollimg'] = $active_sollimg[0];
									$asd[$key]['active_canjia'] = str_count("select * from  kboy_order where order_tuiactive_content = '' and order_tui_content = '' and aid=".$value['id']."  group by uid","order_num");
									$asd[$key]['active_wzhi'] = str_count("select * from  kboy_order where order_tuiactive_content = '' and order_state = 0 and order_tui_content = '' and aid=".$value['id']."  group by uid","order_num");
							} 
									$asd['conut'] =ceil(count($asd)/10);
				
				echo json_encode($asd);
		}
		if($_GET['ming']=='dan'){
			$aid = chkstr(trim($_REQUEST['aid']));
			$chufa = getClassName('kboy_forum_active','active_chufa',"id='$aid'");
			$news_sql = "select * from kboy_order where order_tuiactive_content = '' and order_tui_content = '' and aid='$aid' and order_lahei = 0 order by order_state desc";
			$news_rows = mysql_query($news_sql);
			while($news_rs = mysql_fetch_array($news_rows)){
				$asd[]=$news_rs;
			}
			foreach ($asd as $key => $value) {
				$asd[$key]['nickname']=getUserNickName($value['uid']);
				$asd[$key]['face'] = getClassName("kboy_user","user_face","uid=".$value['uid']);
				if($value['order_qian'] == 1){
					$asd[$key]['mingdan'] = '已签到';
				}else{
					$asd[$key]['mingdan'] = '签到';
				}
			}
			echo json_encode(array('data'=>$asd,'chufa'=>$chufa)); 
		}
		
		if($_GET['xin']=='xi'){
			$oid = chkstr(trim($_REQUEST['oid']));
			$news_sql = "select * from kboy_order where id='$oid'";
			$news_rows = mysql_query($news_sql);
			while($news_rs = mysql_fetch_array($news_rows)){
				$asd=$news_rs;
			}
				$asd['order_phone'] = explode("@@",$asd['order_phone']);
				$asd['order_idcard'] = explode("@@",$asd['order_idcard']);
				$asd['order_realname'] = explode("@@",$asd['order_realname']);
				$asd['order_shangche'] = explode("@@",$asd['order_shangche']);
				$asd['order_sex'] = explode("@@",$asd['order_sex']);
				$asd['order_text']= explode("@@",$asd['order_text']);
				foreach ($asd['order_sex'] as $key => $value) {
					if($value == 1){
						$asd['order_sex'][$key] = '男';
					}elseif($value == 0){
						$asd['order_sex'][$key] = '女';
					}
				}
				if($asd['order_isfull'] == 1){
					$asd['order_isfull'] = '全款';
				}else{
					$asd['order_isfull'] = '预支付';
				}
				if($asd['order_payway'] == 0){
					$asd['order_payway'] = '支付宝';
				}else if($asd['order_payway'] == 2){
					$asd['order_payway'] = '微信';
				}else{
					$asd['order_payway'] = '现场支付';
				}
				if($asd['order_state'] ==1){
					$asd['order_state'] = '已支付';
				}else{
					$asd['order_state'] = '未支付';
				}
			echo json_encode($asd); 
		}
		if($_GET['chu']=='fa'){
			$aid = chkstr(trim($_REQUEST['aid']));
			$news_sql = "update kboy_forum_active set active_chufa=1 where id='$aid'";
			$news_rows = mysql_query($news_sql);
			if($news_rows){
				$uid = getClassName('kboy_forum_active','uid',"id='$aid'");
				$active_all_line = getClassName('kboy_forum_active','active_all_line',"id='$aid'");
				$news_sql = "update kboy_user set user_activetime=user_activetime+1,user_km=user_km+".$active_all_line." where uid='$uid'";
				$news_rows = mysql_query($news_sql);
				if($news_rows){
					echo json_encode(array('allline'=>$active_all_line));
				}else{
					echo json_encode(0);
				}
			}
		}
		if($_GET['shan']=='chu'){
			$oid = chkstr(trim($_REQUEST['oid']));
			$news_sql = "update kboy_order set order_lahei=1 where id='$oid'";
			$news_rows = mysql_query($news_sql);
			if($news_rows){
				echo json_encode(0);
			}else{
				echo json_encode(1);
			}
		}
		if($_GET['bei']=='zhu'){
			$oid = chkstr(trim($_REQUEST['oid']));
			$order_beizhu = chkstr(trim($_REQUEST['beizhu']));
			$news_sql = "update kboy_order set order_beizhu='".$order_beizhu."' where id='$oid'";
			$news_rows = mysql_query($news_sql);
			if($news_rows){
				echo json_encode(1);
			}else{
				echo json_encode(0);
			}
		}
	}
?>